<?php
/**
 * Mamangeacount_Data_Currentaccount
 * current account data
 * @author adrian
 */
class Manageaccount_Data_Currentaccount implements Manageaccount_Data_Mainable, 
        Manageaccount_Data_Preparable, Manageaccount_Data_Tokenable {
    
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    /**
     *
     * @var type $token
     * token handler
     */
    public $token;
    /**
     *
     * @var type $database_query
     * database query handler
     */
    public $database_query;
    
    /**
     * construct()
     */
    public function __construct() {
        $this->database = new Core_Driver_MysqlImproved;
    }
    
    /**
     * main()
     * get current user data
     * 
     * @param array $variables
     * @return type $page
     */
    public function main(array $variables = null) {
        $this->database->connect();
        foreach($_SESSION as $key => $value){
            $_SESSION[$key] = $this->database->escape($value);
        }
        $this->prepare_query($_SESSION);
        //echo $this->database_query;
        //var_dump($variables);
        //die();
        $this->database->prepare($this->database_query);
        $this->database->query();
        $page = array();
        $page = $this->database->fetch('array');
        $page['template'] = SERVER_ROOT."manageaccount/views/manageaccount.php";
        $page['csrf_token'] = $this->create_token();
        //var_dump($page);
        //die();
        return $page;
    }
    /**
     * create_token()
     * crate only use token
     * 
     * @return type tokenizer
     */
    public function create_token() {
        $this->token = new Core_Data_Tokenizer;
        return $this->token->create_token();
    }
    
    /**
     * prepare_query()
     * set database query
     * 
     * @param array $variables
     */
    public function prepare_query(array $variables = null) {
        $this->database_query = "SELECT "
                . "*"
                . " FROM "
                . "users_data"
                . " WHERE "
                . "users_data.id="
                .$variables['user_id'].
                ";";
    }

}
